package com.df.actions;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.df.managers.NewsManager;
import com.df.managers.TypeManager;
import com.df.news.News;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype") 
public class NewsAction extends ActionSupport {
	@Resource
	private TypeManager typeManager;
	@Resource
	private NewsManager newsManager;
	private String page = "index";
	private News news;
	private int id;
	private int typeId = -1;
	private String showName;
	private int count;
	private int size;
	public int getSize() {
		return size;
	}


	public void setSize(int size) {
		this.size = size;
	}


	public String addInput() throws Exception {
		List typeList = typeManager.list();
		ActionContext.getContext().put("list", typeList);
		page = "add";
		return SUCCESS;
	}
	
	
	public String add(){
		newsManager.add(news);
		return "pub_add";
	}
	
	public String execute(){
	    ActionContext.getContext().put("pm", newsManager.list(typeId));
	    ActionContext.getContext().put("list", typeManager.list());
	    ActionContext.getContext().put("typeId",typeId);
	    //page = "";
		return SUCCESS;
	}

	public String updateInput(){
		news = newsManager.getById(id);
		List typeList = typeManager.list();
		ActionContext.getContext().put("list", typeList);
		page = "add";
		return SUCCESS;
	}
	public String del(){
		newsManager.del(id);
		return "pub_del";
	}

	public String findByTypeAndCount() {
		// TODO Auto-generated method stub
		List<News> list = newsManager.findByTypeAndCount(showName,count);
		ActionContext.getContext().put("list", list);
		return SUCCESS;
	}
	public String findByShowName(){
		news = newsManager.findByShowName(showName);
		return SUCCESS;
	}
	public String serchByTypeAndCount() {
		 ActionContext.getContext().put("pm", newsManager.list(showName));
		 ActionContext.getContext().put("type", typeManager.getById(showName));
		return SUCCESS;
	}
	
	public String findById(){
		news = newsManager.getById(id);
		return SUCCESS;
	}
	public TypeManager getTypeManager() {
		return typeManager;
	}
	public void setTypeManager(TypeManager typeManager) {
		this.typeManager = typeManager;
	}
	public NewsManager getNewsManager() {
		return newsManager;
	}
	public void setNewsManager(NewsManager newsManager) {
		this.newsManager = newsManager;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}


	public News getNews() {
		return news;
	}


	public void setNews(News news) {
		this.news = news;
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}



	public int getTypeId() {
		return typeId;
	}


	public void setTypeId(int typeId) {
		this.typeId = typeId;
	}


	public int getCount() {
		return count;
	}


	public void setCount(int count) {
		this.count = count;
	}


	public String getShowName() {
		return showName;
	}


	public void setShowName(String showName) {
		this.showName = showName;
	}
}
